#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int before(char *key, char n)
{
	if (key[2] == n) return 1;
	else return 0;
}

int after(char *key, char n)
{
	if (key[0] == n) return 1;
	else return 0;
}

int main()
{
	FILE *fp;
	fp = fopen("keylog.txt", "r");
	char *keys[50], n, b[200];
	int i=0, j=0;
	while(i <50) {
		keys[i] = (char *)malloc(sizeof(char)*3);
		fscanf(fp, "%s", keys[i]);
		//printf("%s", keys[i]);
		i++;
	}
	fclose(fp);
	i = 0;
	b[0] = keys[0][0];
	while (i<50) {
		if (after(keys[i], b[j])) strncpy(b+j, keys[i++], 3);
		printf("%s\n", b);
		j +=2;
	}
 	b[j] = '\0';
	printf("%s\n", b);
	while(i<50)printf("%s\n", keys[i++]);

}
